﻿using System;
using System.Collections.Generic;
using System.Text;
using WorldExchange;
using System.Xml;
using System.IO;
using System.Configuration;
using System.Web;
using HtmlAgilityPack;
using DatabaseService;

namespace WorldGoldenPrice
{
    public class GoldenPriceACB : GoldenPrice
    {
        public override void getPrice()
        {
            this.WorldBuy = "";
            this.WorldSell = "";
            this.VnBuy = "";//Temp
            this.VnSell = "";//Temp

            this.LinkService = ConfigurationSettings.AppSettings["GoldPrice_WebService_ACB"].ToString().Trim();
            XmlDocument xmldoc = new XmlDocument();
            try
            {
                string strXML = WebTool.getWebContent(this.LinkService);
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(strXML);
                this.WorldBuy = doc.GetElementbyId("igmxaubidprice").InnerText;
                this.WorldSell = doc.GetElementbyId("igmxauofferprice").InnerText;

                 Single wBuy = Convert.ToSingle(this.WorldBuy);
                  Single wSell = Convert.ToSingle(this.WorldSell);


                  //Exchange TGNT =WorldExchange.Exchange.UniqueInstance;
                  Exchange_Factory TGNT = AccessDB.getExchangeInfo();
                  Single exRate = Convert.ToSingle(TGNT.USD.Ban);

                  this.VnBuy = (((wBuy + 0) * 1.0 * 1.205656 * exRate + 0) / 1000).ToString("#,###");
                  this.VnSell = (((wSell + 0) * 1.0 * 1.205656 * exRate + 0) / 1000).ToString("#,###");

                  // lay gia dau ,usd tung Record gan nhat

                 GoldenPrice_Factory tem= AccessDB.getProductInfo();

                 this.OilBuy = tem.OilBuy;
                 this.OilSell = tem.OilSell;
                 this.EURUSD = tem.EURUSD;
                 this.GBPUSD = tem.GBPUSD;
                 this.USDJPY = tem.USDJPY;
                 this.USDCAD = tem.USDCAD;
                 this.AUDUSD = tem.AUDUSD;
                 this.NZDUSD = tem.NZDUSD;
                 this.USDNOK = tem.USDNOK;
                  
            }
            catch (Exception ex)
            {

                TLog.WriteErr("GoldenPriceACB : getPrice", ex.ToString());
            }
            setNewValue();
         
        }


    }

}